//
//  HistoryTableViewCell1.m
//  My1A2B
//
//  Created by sun ives on 2010/1/11.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "HistoryTableViewCell1.h"
#import "define_tw.h"

#define EDITING_INSET       10.0
#define TEXT_LEFT_MARGIN    8.0
#define TEXT_RIGHT_MARGIN   5.0
#define PREP_TIME_WIDTH     160.0

@implementation HistoryTableViewCell1
@synthesize m_uiNumber, m_uiResult, guess;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
	
	if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {		
        m_uiNumber = [[UILabel alloc] initWithFrame:CGRectZero];
        [m_uiNumber setFont:[UIFont boldSystemFontOfSize:16.0]];
        [m_uiNumber setTextColor:[UIColor blackColor]];
        [m_uiNumber setHighlightedTextColor:[UIColor whiteColor]];
        [self.contentView addSubview:m_uiNumber];
		
        m_uiResult = [[UILabel alloc] initWithFrame:CGRectZero];
        [m_uiResult setFont:[UIFont boldSystemFontOfSize:16.0]];
        [m_uiResult setTextColor:[UIColor blackColor]];
        [m_uiResult setHighlightedTextColor:[UIColor whiteColor]];
        [self.contentView addSubview:m_uiResult];
		
    }
	
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
	
    [m_uiNumber setFrame:[self _numberFrame]];
    [m_uiResult setFrame:[self _resultFrame]];
}
- (CGRect)_numberFrame{
	return CGRectMake(TEXT_LEFT_MARGIN, 4.0, self.contentView.bounds.size.width  - TEXT_RIGHT_MARGIN * 2 - PREP_TIME_WIDTH, 32.0);
}
- (CGRect)_resultFrame {
    CGRect contentViewBounds = self.contentView.bounds;
    return CGRectMake(contentViewBounds.size.width - PREP_TIME_WIDTH - TEXT_RIGHT_MARGIN, 4.0, PREP_TIME_WIDTH, 32.0);
}

- (void)setGuess:(strGuess)currGuess{
	NSString *number, *result;
	if (&currGuess) {
		guess = currGuess;
		number = [[NSString alloc] initWithFormat:NUMBER, guess.number];
		result = [[NSString alloc] initWithFormat:RESULT, guess.result];
	}else {
		number = [[NSString alloc] initWithFormat:@"ERROR"];
		result = [[NSString alloc] initWithFormat:@"ERROR"];
	}
	m_uiNumber.text = number;
	m_uiResult.text = result;
	[number release];
	[result release];
}


@end
